FBDEditor.model.prototype.pascalCodeCreator = function ( moduleId, x ) {
/*
    pascalCodeCreator for FBDEditor 1.0
    Copyright (C) 2008-2009 Yuriy Butenko y.v.butenko@gmail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/// x: { "v":[..], "f":[..], "i":[..], "o":[..], "txt":[..] };
	var res = 'Unit ' + moduleId + ';\n\nInterface\n\nType\n' + moduleId + ' = Object\n';
	var regExpIdTp = /^\s*([^\s]+)\s*(\:\s*([^\s]*)\s*)?$/;
	res += '(* Inputs *)\n';
	for ( var i in x.i ) {
		var r = regExpIdTp.exec( x.i[i] );
		res += '\t' + r[1] + ':' + ( r[3] || "Longint" ) + ';\n';
	};
	res += '(* Outputs *)\n';
	for ( var i in x.o ) {
		var r = regExpIdTp.exec( x.o[i] );
		res += '\t' + r[1] + ':' + ( r[3] || "Longint" ) + ';\n';
	};
	res += '(* FB *)\n';
	for ( var i in x.f ) {
		var cls = x.f[i][1];
		var r = regExpIdTp.exec( x.f[i][0] );
		res += '\t' + r[1] + ': ' + cls + ';\n';
	};
	for ( var i in x.v ) {
		var r = regExpIdTp.exec( x.v[i] );
		res += '\t' + r[1] + ':' + ( r[3] || "Longint" ) + ';\n';
	};
	res += '\tProcedure init;\n\tProcedure eval;\nEnd;\n\nImplementation\n\n';
	res += 'Procedure ' + moduleId + '.init;\nBegin\n';
	for ( var i in x.f ) {
		var r = regExpIdTp.exec( x.f[i][0] );
		res += '\t' + r[1] + '.init();\n';
	};
	res += 'End;\n\n';
	res += 'Procedure ' + moduleId + '.eval;\n';
	res += 'Begin\n';
	var c = x.txt;
	for ( var i in c ) {
		var dstId = regExpIdTp.exec( c[i][1] ), dstFld = c[i][2];
		switch ( c[i][0] ) {
			case 'cset':
				res += '\t' + dstId[1] + ( dstFld ? "." + dstFld : "" ) + ' := ' + c[i][3] + ';\n';
				break;
			case 'set':
				var srcId = regExpIdTp.exec( c[i][3] ), srcFld = c[i][4];
				res += '\t' + dstId[1] + ( dstFld ? "." + dstFld : "" ) + ' := '
					+ srcId[1] + ( srcFld ? "." + srcFld : "" ) + ';\n';
				break;
			case 'call':
				res += '\t' + dstId[1] + '.eval;\n';
				break;
		};
	};
	res += 'End;\n\n';
	res += 'End.\n';
	return res;
}
FBDEditor.model.prototype.pascalCodeCreator.fileExt = ".pas";
